<template>
  <div>

    <el-card shadow="never" dis-hover class="ivu-mt ">
      <el-table
          :data="dataList"
          ref="table"
          class="mt25"
          :loading="loading"
          highlight-current-row
      >
        <el-table-column prop="id" label="游戏记录ID">
        </el-table-column>
        <el-table-column prop="uid" label="用户昵称">
		   <template slot-scope="scope">
			  <router-link :to="{ path: $routeProStr + '/user/list?uid='+scope.row.uid }">
				{{scope.row.nickname}}
			  </router-link>
		  </template>
        </el-table-column>
        <el-table-column prop="room_id" label="房间编号">
		   <template slot-scope="scope">
			  <router-link :to="{ path: $routeProStr + '/crud/wwj_room?room_id='+scope.row.room_id }">
				{{scope.row.room_id}}
			  </router-link>
		  </template>
        </el-table-column>
        <el-table-column prop="product_id" label="商品名称">
		   <template slot-scope="scope">
			  <router-link :to="{ path: $routeProStr + '/product/product_list?store_name='+scope.row.store_name }">
				{{scope.row.store_name}}
			  </router-link>
		  </template>
        </el-table-column>
        <el-table-column prop="lottery" label="是否中奖">
            <template slot-scope="scope">
				{{scope.row.lottery | convert_lottery }}
            </template>
        </el-table-column>
        <el-table-column prop="batch_num" label="中奖批次">
        </el-table-column>
        <el-table-column prop="add_time" label="添加时间">
            <template slot-scope="scope">
				{{scope.row.add_time | timeFormat }}
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
              <a @click="show(scope.row)">详情</a>
              <!-- <el-divider direction="vertical" />
              <a @click="edit(scope.row.id)">修改</a> -->
              <el-divider direction="vertical" />
              <a @click="del(scope.row, '删除', scope.$index)">删除</a>
            </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <pagination :total="total"  @pagination="pageChange"  :limit.sync="from.limit" :page.sync="from.page" />
      </div>
    </el-card>

    <el-dialog title="查看详情" :visible.sync="dialogTableVisible" v-if='dialogTableVisible'>
        <el-descriptions title="游戏记录详细">
            <el-descriptions-item label="游戏记录ID">{{info.id}}</el-descriptions-item>
            <el-descriptions-item label="用户昵称">
				<router-link :to="{ path: $routeProStr + '/user/list?uid='+info.uid }">
					{{info.nickname}}
				</router-link>			
			</el-descriptions-item>
            <el-descriptions-item label="房间编号">
				<router-link :to="{ path: $routeProStr + '/crud/wwj_room?room_id='+info.room_id }">
					{{info.room_id}}
				</router-link>		
			</el-descriptions-item>
            <el-descriptions-item label="商品名称">
				<router-link :to="{ path: $routeProStr + '/product/product_list?store_name='+info.store_name }">
					{{info.store_name}}
				</router-link>
			</el-descriptions-item>
            <el-descriptions-item label="是否中奖">{{info.lottery | convert_lottery}}</el-descriptions-item>
            <el-descriptions-item label="中奖批次">{{info.batch_num}}</el-descriptions-item>
            <el-descriptions-item label="添加时间">{{info.add_time | timeFormat }}</el-descriptions-item>

        </el-descriptions>
    </el-dialog>

  </div>
</template>

<script>
import dayjs from 'dayjs';
import { mapState } from 'vuex';
import { gameRecordSaveApi, gameRecordStatusApi, gameRecordDeleteApi, gameRecordUpdateApi, getGameRecordCreateApi, getGameRecordEditApi, getGameRecordListApi, getGameRecordReadApi} from '@/api/crud/gameRecord';
export default {
  name: 'game_record',
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      loading: false,
      from: {
        page: 1,
        limit: 15,
      },
      dataList: [],
      total: 0,
      dialogTableVisible: false,
      info: {},
    };
  },
  filters: {
    timeFormat(value, birthday) {
      let i = birthday ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss';
      if (!value) {
        return '-';
      }
      return dayjs(value * 1000).format(i);
    },
    convert_lottery(value) {
      if (value == 1) {
        return '中奖';
      } else if (value == 0) {
        return '不中';
      } else {
        return '未知';
      }
    },
  },
  computed: {
    ...mapState('media', ['isMobile']),
    labelWidth() {
      return this.isMobile ? undefined : '75px';
    },
    labelPosition() {
      return this.isMobile ? 'top' : 'left';
    },
  },
  created() {
    this.getList();
  },
  methods: {
    show(row) {
        getGameRecordReadApi(row.id).then(res => {
           this.dialogTableVisible = true;
           this.info = res.data;
        }).catch(res => {
          this.$Message.error(res.msg);
        })
    },
    //修改状态
    updateStatus(row, field) {
        gameRecordStatusApi(row.id, {field: field, value: row[field]})
        .then(async (res) => {
          this.$message.success(res.msg);
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 添加
    add() {
      this.$modalForm(getGameRecordCreateApi()).then(() => this.getList());
    },
    // 表格搜索
    searchs() {
      this.from.page = 1;
      this.getList();
    },
    //列表
    getList() {
      this.loading = true;
      getGameRecordListApi(this.from)
          .then(async (res) => {
            let data = res.data;
            this.dataList = data.list;
            this.total = data.count;
            this.loading = false;
          })
          .catch((res) => {
            this.loading = false;
            this.$Message.error(res.msg);
          });
    },
    //分页
    pageChange(index) {
      this.from.page = index;
      this.getList();
    },
    // 修改
    edit(id) {
      this.$modalForm(getGameRecordEditApi(id)).then(() => this.getList());
    },
    // 删除
    del(row, tit, num) {
      let delfromData = {
        title: tit,
        num: num,
        url: `crud/game_record/${row.id}`,
        method: 'DELETE',
        ids: '',
      };
      this.$modalSure(delfromData)
          .then((res) => {
            this.$Message.success(res.msg);
            this.getList();
          })
          .catch((res) => {
            this.$Message.error(res.msg);
          });
    },
  },
};
</script>

<style scoped lang="stylus"></style>
